<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/WEB-INF/pages/include/prelude.jspf"%>
<%@include file="/WEB-INF/pages/include/common.jspf"%>
<link href="<c:url value='/static/css/memberInfo.css' />" type="text/css" rel="stylesheet"/>
<title>新增国内乘机人</title>
<script type="text/javascript" src="<c:url value='/static/js/validate.js' />"></script>
<script type="text/javascript">
$(function(){
	var title = ${update_flag =='0'};
	if(title){
		$("#pagetitle").html('修改国内乘机人');
	}else{
		$("#pagetitle").html('新增国内乘机人');
	}
});
/**
 * 表单验证
 */
function submitForm(){
	
	if(!IsNull('familyNameCn', '姓')){
		return false;
	}

	if(!IsNull('firstNameCn', '名')){
		return false;
	}
	if(!IsNull('certNrb', '证件号码')){
		return false;
	}
	if(!IsNull('mobile', '手机号码')){
		return false;
	}
	
	var certType = $("#certType").val();
	if(certType == 'ID_CARD'){
		var cardNo = $("#certNrb").val();
		
		if(!isIdCardNo(cardNo)){
			return false;
		}
	}
	
	var mobile = $("#mobile").val();
	if(!validatemobile(mobile)){
		return false;
	}
	$("#form").submit();
}

/**
 * 手机号码验证
 */
function validatemobile(mobile)
{  
    if(mobile.length!=11)
    {
        alert('请输入有效的手机号码！');
        return false;
    }
    var myreg = /^1[0-9]{10}$/;
    if(!myreg.test(mobile))
    {
        alert('请输入有效的手机号码！');
        return false;
    }
    return true;
}



/**
 * 身份证号码验证
 */
function isIdCardNo(num)  {
	num = num.toUpperCase();
	
	//身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X。              
	if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num))){                 
		alert('输入的身份证号长度不对，或者号码不符合规定！\n15位号码应全为数字，18位号码末位可以为数字或X。');
		return false;           
	} 
	//校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。  
	//下面分别分析出生日期和校验位  
	var len, re;  len = num.length; 
	
	//1900
	if (len == 15){  
		re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);  
		var arrSplit = num.match(re);    
		//检查生日日期是否正确  
		var dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4]);  
		var bGoodDay;  
		bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));  
		if (!bGoodDay)  {           
			alert('输入的身份证号里出生日期不对！');               
			return false;  
		} 
	}  
	if (len == 18){  
		re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);  
		var arrSplit = num.match(re);    
		//检查生日日期是否正确  
		var date = new Date();
		var newYear = date.getFullYear();//当前年
		//alert("输入的年是:"+newYear);
		
		var iCurrentYear =  parseInt(arrSplit[2]);
		var iCurrentMonth =  parseInt(arrSplit[3]);
		var iCurrentDay =  parseInt(arrSplit[4]);
		
		if(iCurrentYear < 1900 || newYear<iCurrentYear){
			alert("输入的身份证号码，年份不合法");
			return false;
		}
		if((iCurrentMonth)>12){
			alert("输入的身份证号码，月份最大为12！");
			return false;
		}
		if(iCurrentDay>31){
			alert("输入的身份证号码出生日不合法，最大为31！");
			return false;
		}
		var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);  
		var bGoodDay;  bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));  
		if (!bGoodDay)  {  
			alert(dtmBirth.getYear());  
			alert(arrSplit[2]);  
			alert('输入的身份证号里出生日期不对！'); 
			return false;  
		}
		return true;
	}  
	return false; 
}      
</script>
</head>
<body>
<div data-role="page">
	<%@include file="/WEB-INF/pages/include/header.jsp"%>
	<div data-role="content">
	  <form id="form" action="<c:url value='/member/addCustomerInfo.do'/>" method="post" data-ajax="false">
	  	
	  	<input type="hidden" name="synchronousStatus" value="${customer==null? '':customer.synchronousStatus}" />
	  	<input type="hidden" name="searchId" value="${searchId }" />
		<input type="hidden" name="index" value="${index }"  />
	  	<input type="hidden" name="routerType" value="D" />
	  	<input type="hidden" name="count" value="${count }" />
	  	<input type="hidden" name="customerIds" value="${customerIds }"  />
		<input type="hidden" id="guestId" name="guestId" value="${guestId }"  />
		<input type="hidden" name="adultCount" value="${adultCount }"  />
		<input type="hidden" id="childCount" name="childCount" value="${childCount }"  />
		<div class="m_item">
			<div class="m_title">旅客信息</div>
			<ul>
				<li>

				<div class="i_label"><span class="xh">*</span>旅客类型：</div>
				        <input data-role="none" type="radio" name="travelerType" <c:if test="${'ADT' eq (customer==null? 'ADT':customer.travelerType)}">checked="checked"</c:if> id="radio-view-a" value="ADT" class="radio" />
			         	<label for="radio-view-a" class="radio">成人</label>
			         	<input data-role="none" type="radio" name="travelerType" <c:if test="${'CNN' eq (customer==null? '':customer.travelerType)}">checked="checked"</c:if> id="radio-view-b" value="CNN" class="radio"  />
			         	<label for="radio-view-b" class="radio">儿童</label>
					<div class="clear"></div>
				
				<!-- <div class="i_label"><span class="xh"></span>旅客类型：</div><b>成人</b>
					<input data-role="none" id="travelerType" name="travelerType" value="ADT" type="hidden" class="txt" />
					<div class="clear"> </div>-->
				</li>
				<li><div class="i_label"><span class="xh">*</span>姓：</div><input data-role="none" id="familyNameCn" value="${customer==null? '':customer.familyNameCn}" name="familyNameCn" type="text" class="txt" /><div class="clear"></div></li>
				<li><div class="i_label"><span class="xh">*</span>名：</div><input data-role="none" id="firstNameCn" value="${customer==null? '':customer.firstNameCn}" name="firstNameCn" type="text" class="txt" /><div class="clear"></div></li>
				<li><div class="i_label"><span class="xh"></span>证件类别：</div>
					<select data-role="none" name="certType" id="certType" onchange="$(this).blur()" class="txt" >
						<option class="optxt" value="">（选择）</option>
						<option class="optxt"  <c:if test="${'2.DOC' eq (customer==null? '':customer.certType)}">selected</c:if>  value="2.DOC">护照</option>
						<option class="optxt"  <c:if test="${'ID_CARD' eq (customer==null? '':customer.certType)}">selected</c:if> value="ID_CARD" selected="selected">身份证</option>
						<option class="optxt"  <c:if test="${'MI_CARD' eq (customer==null? '':customer.certType)}">selected</c:if> value="MI_CARD">军官证或其它证件</option>
					</select>	
					<div class="clear"></div>
				</li>
				<li><div class="i_label"><span class="xh">*</span>证件号码：</div><input data-role="none" id="certNrb" name="certNrb" value="${customer==null? '':customer.certNrb}" type="text" class="txt" /><div class="clear"></div></li>
				<li><div class="i_label"><span class="xh"></span><span style="font-size:0.8em;">常旅客计划：</span></div>
					<select data-role="none" name="phCardType" id="phCardType" onchange="$(this).blur()" class="txt">
					
						<option class="optxt" value="" selected="selected">请选择</option>
						<option class="optxt" <c:if test="${'CA' eq (customer==null? '':customer.phCardType)}">selected</c:if> value="CA">凤凰知音会员</option>
						<option class="optxt" <c:if test="${'STAR_ALLIANCE' eq (customer==null? '':customer.phCardType)}">selected</c:if> value="STAR_ALLIANCE">其他星空联盟航空公司会员</option>
					</select>	
					<div class="clear"></div>
				</li>
				<li><div class="i_label"><span class="xh"></span>会员号：</div><input data-role="none" id="phCardNbr" value="${customer==null? '':customer.phCardNbr}" name="phCardNbr" type="text" class="txt" /><div class="clear"></div></li>
				<li><div class="i_label"><span class="xh">*</span>手机号码：</div><input data-role="none" id="mobile" value="${customer==null? '':customer.mobile}" onkeyup="value=this.value.replace(/\D+/g,'')" name="mobile" type="text" class="txt" /><div class="clear"></div></li>
			</ul>
		</div>
		<br />
		<div>
		<c:choose>
			<c:when test="${update_flag =='0'}">
				<input type="hidden" value="${customer.id }" name="id" />
				<input type="hidden" value="0" name="update_flag" />
				<button class="btn" onclick="submitForm(0);" data-theme="a" type="button">修改</button>
			</c:when>
			<c:otherwise>
				<button class="btn" onclick="submitForm();" data-theme="a" type="button">添加</button>
			</c:otherwise>
		</c:choose>
		</div>
	  </form>
	</div>
</div>
</body>
</html>